#pragma once

namespace MnistDigit
{

	class Endiannes
	{
	private:
		template<class TData>
		static void ByteSwap(TData& data)
		{
			int i = 0;
			int j = sizeof(data)-1;
			unsigned char* const byte = reinterpret_cast<unsigned char*>(&data);
			while (i<j)
			{
				std::swap(byte[i], byte[j]);
				++i;
				--j;
			}
		}

		static bool GetBigEndian();
		static bool IsBigEndian();
	public:
		template<class TData>
		static void MSB2OS(TData& data)
		{
			if(!IsBigEndian())
				ByteSwap(data);
		}

		template<class TData>
		static void LSB2OS(TData& data)
		{
			if(IsBigEndian())
				ByteSwap(data);
		}
	};
}